package com.hspedu.tankgame4;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;


/**
 * @author DL5O
 * @version 1.0
 */
public class YwlTankGame04 extends JFrame {
    MyPanel mp = null;
    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        YwlTankGame04 ywlTankGame04 = new YwlTankGame04();
    }

    public YwlTankGame04(){
        //用于判断开始新游戏还是继续上一局游戏
        System.out.println("请输入选择\n1: 新游戏 \n2: 继续上一局");
        String key = "";
        while(true ){
            key = sc.next();
            if(key.equals("1") || key.equals("2")){
                break;
            }
            System.out.println("输入有误请重新输入!");
            System.out.println("请输入选择\n1: 新游戏 \n2: 继续上一局");
        }


        mp = new MyPanel(key);
        Thread thread_mp = new Thread(mp);
        thread_mp.start();
        this.add(mp);//把面板(就是游戏的绘图区域)塞进去
        this.setSize(1300,950);
        this.addKeyListener(mp);//对键盘事件进行监听
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗口关闭选项后的动作
        this.setVisible(true);//设置是否可见

        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.keepRecord();
                System.exit(0);
            }
        });
    }

}
